package com.epigeon.amadeo.test;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.epigeon.amadeo.engine.Engine;
import com.epigeon.amadeo.engine.EngineConfiguration;
import com.epigeon.amadeo.impl.PassiveEditText;
import com.epigeon.amadeo.impl.XMPPConnectionInput;

public class XMPPDemo extends Activity {
	
	public static final String TAG_TEXT_MESSAGE = "text_message";
	public static final String TAG_TEXT_RECIPIENT = "text_recipient";
	public static final String TAG_BUTTON_SEND = "button_send";
	public static final String TAG_LIST_MESSAGES = "list_messages";
	public static final String TAG_XMPP_CONNECTION = "xmpp_connection";
	
	private Context context;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.context = this;
        setContentView(R.layout.main);

        PassiveMessageList messageList = (PassiveMessageList) findViewById(R.id.listMessages);        
        PassiveEditText textMessage = (PassiveEditText) findViewById(R.id.sendText);
        PassiveEditText textRecipient = (PassiveEditText) findViewById(R.id.recipient);
        ActiveSendButton sendButton = (ActiveSendButton) findViewById(R.id.send);     
        XMPPConnectionInput con = new XMPPConnectionInput();
        
        sendButton.addPassiveInput(textMessage);
        sendButton.addPassiveInput(textRecipient);
        
        EngineConfiguration configuration = new EngineConfiguration(this, R.raw.amadeo);
        Engine.getInstance().setEngineConfiguration(configuration);
        
        Engine.getInstance().registerOutput(TAG_LIST_MESSAGES, messageList);
        Engine.getInstance().registerOutput(TAG_XMPP_CONNECTION, con);
        Engine.getInstance().registerInput(TAG_TEXT_MESSAGE, textMessage);
        Engine.getInstance().registerInput(TAG_TEXT_RECIPIENT, textRecipient);
        Engine.getInstance().registerInput(TAG_BUTTON_SEND, sendButton);
        Engine.getInstance().registerInput(TAG_XMPP_CONNECTION, con);
        
        Button settingsButton = (Button) findViewById(R.id.setup);
        settingsButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				(new SettingsDialog(context)).show();
			}        	
        });
    }
}